package com.seeyon.apps.brwh.manager.impl;

import com.seeyon.apps.brwh.kit.StrKit;
import com.seeyon.apps.brwh.manager.SencondDatailManager;
import com.seeyon.apps.brwh.po.SencondDatailPO;
import com.seeyon.ctp.util.DBAgent;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 二级明细扩展Manager实现
 */
public class SencondDatailManagerImpl implements SencondDatailManager {

    @Override
    public void save(SencondDatailPO sencondDatailPO) {
        DBAgent.save(sencondDatailPO);
    }

    @Override
    public SencondDatailPO findDataByMasterId(String masterId) {
        String hql =" from SencondDatailPO where masterId = :masterId ";
        Map<String, Object> parameterMap = new HashMap<String, Object>();
        parameterMap.put("masterId", masterId);
        List<SencondDatailPO> list = DBAgent.find(hql, parameterMap);
        if(!list.isEmpty()) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public List<SencondDatailPO> findAllDatas() {
        String hql =" from SencondDatailPO";
        Map<String, Object> parameterMap = new HashMap<String, Object>();
        return DBAgent.find(hql, parameterMap);
    }

    @Override
    public List<SencondDatailPO> findDatasByMap(Map<String, Object> map) {
        String recordId = StrKit.str(map.get("recordId"));
        String masterId = StrKit.str(map.get("masterId"));

        String hql =" from SencondDatailPO where 1=1 ";
        if(!recordId.equals("")){
            hql += " and recordId = :recordId";
        }
        if(!masterId.equals("")){
            hql += " and masterId = :masterId";
        }
        return DBAgent.find(hql, map);
    }

    @Override
    public void updateAccountLockRecord(SencondDatailPO sencondDatailPO) {
        DBAgent.merge(sencondDatailPO);
    }
}
